<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>uniapp开发app - 4.uniapp里echart的使用 | 云游</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="favicon.ico">
    <script src="/live2dw/L2Dwidget.min.js"></script>
    <script src="/live2dw/L2Dwidget.0.min.js"></script>
    <script src="/live2dw/initLine2dw.js"></script>
    <link rel="stylesheet" href="/live2dw/initLine2dw.css">
    <meta name="description" content="仰天大笑出门去">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.746f5c46.css" as="style"><link rel="preload" href="/assets/js/app.8ca67ad1.js" as="script"><link rel="preload" href="/assets/js/3.dc5e7bc7.js" as="script"><link rel="preload" href="/assets/js/1.f19b5812.js" as="script"><link rel="preload" href="/assets/js/52.ace084da.js" as="script"><link rel="prefetch" href="/assets/js/10.063f4d84.js"><link rel="prefetch" href="/assets/js/11.7aaafe6d.js"><link rel="prefetch" href="/assets/js/12.1d3cbcb7.js"><link rel="prefetch" href="/assets/js/13.3eff3441.js"><link rel="prefetch" href="/assets/js/14.d011e66e.js"><link rel="prefetch" href="/assets/js/15.64da65a0.js"><link rel="prefetch" href="/assets/js/16.afe5f3d7.js"><link rel="prefetch" href="/assets/js/17.9645712f.js"><link rel="prefetch" href="/assets/js/18.8acac1b3.js"><link rel="prefetch" href="/assets/js/19.211aa7fa.js"><link rel="prefetch" href="/assets/js/20.33c40850.js"><link rel="prefetch" href="/assets/js/21.a5f61bc3.js"><link rel="prefetch" href="/assets/js/22.3f31af86.js"><link rel="prefetch" href="/assets/js/23.c1a2f360.js"><link rel="prefetch" href="/assets/js/24.f92207d5.js"><link rel="prefetch" href="/assets/js/25.3859fc8e.js"><link rel="prefetch" href="/assets/js/26.c3bb43ea.js"><link rel="prefetch" href="/assets/js/27.2d3ac28b.js"><link rel="prefetch" href="/assets/js/28.5eba4e00.js"><link rel="prefetch" href="/assets/js/29.591a72c1.js"><link rel="prefetch" href="/assets/js/30.4b4e3dae.js"><link rel="prefetch" href="/assets/js/31.0c3aac1f.js"><link rel="prefetch" href="/assets/js/32.927b230d.js"><link rel="prefetch" href="/assets/js/33.4ecffa3d.js"><link rel="prefetch" href="/assets/js/34.b9bc1b48.js"><link rel="prefetch" href="/assets/js/35.42f94296.js"><link rel="prefetch" href="/assets/js/36.95b6cc33.js"><link rel="prefetch" href="/assets/js/37.f3505924.js"><link rel="prefetch" href="/assets/js/38.19c4c627.js"><link rel="prefetch" href="/assets/js/39.592f8fae.js"><link rel="prefetch" href="/assets/js/4.47f43f55.js"><link rel="prefetch" href="/assets/js/40.e4393725.js"><link rel="prefetch" href="/assets/js/41.66b5758c.js"><link rel="prefetch" href="/assets/js/42.b0eb455d.js"><link rel="prefetch" href="/assets/js/43.11fab467.js"><link rel="prefetch" href="/assets/js/44.cd6e5a73.js"><link rel="prefetch" href="/assets/js/45.b3e3b872.js"><link rel="prefetch" href="/assets/js/46.07a07f51.js"><link rel="prefetch" href="/assets/js/47.c2287444.js"><link rel="prefetch" href="/assets/js/48.66123573.js"><link rel="prefetch" href="/assets/js/49.bebbe116.js"><link rel="prefetch" href="/assets/js/5.e8c05b51.js"><link rel="prefetch" href="/assets/js/50.70436f90.js"><link rel="prefetch" href="/assets/js/51.18985c0f.js"><link rel="prefetch" href="/assets/js/53.02616c91.js"><link rel="prefetch" href="/assets/js/54.6eb33990.js"><link rel="prefetch" href="/assets/js/55.733d5e7a.js"><link rel="prefetch" href="/assets/js/56.36ca4523.js"><link rel="prefetch" href="/assets/js/57.80493e39.js"><link rel="prefetch" href="/assets/js/58.34b95d6c.js"><link rel="prefetch" href="/assets/js/59.96be3833.js"><link rel="prefetch" href="/assets/js/6.027fb3c9.js"><link rel="prefetch" href="/assets/js/60.214c4180.js"><link rel="prefetch" href="/assets/js/61.ba0ebff0.js"><link rel="prefetch" href="/assets/js/62.09089206.js"><link rel="prefetch" href="/assets/js/63.a5c5aa3e.js"><link rel="prefetch" href="/assets/js/64.2d5fc9ca.js"><link rel="prefetch" href="/assets/js/65.c8171d3c.js"><link rel="prefetch" href="/assets/js/66.6d4bbf9e.js"><link rel="prefetch" href="/assets/js/67.ceeafab4.js"><link rel="prefetch" href="/assets/js/68.16d3218f.js"><link rel="prefetch" href="/assets/js/7.b5f855a8.js"><link rel="prefetch" href="/assets/js/8.5ac3177c.js"><link rel="prefetch" href="/assets/js/9.8e7f0e06.js">
    <link rel="stylesheet" href="/assets/css/0.styles.746f5c46.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-1aefc0b4><div data-v-1aefc0b4><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1aefc0b4 data-v-1aefc0b4><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>云游</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>仰天大笑出门去</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>fhtwl</span>
            
          <!---->
          2022
        </a></span></div></div> <div class="hide" data-v-1aefc0b4><header class="navbar" data-v-1aefc0b4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">云游</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/其它/" class="nav-link"><i class="undefined"></i>
  其它
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeLine/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><a href="https://github.com/fhtwl/fhtwl.github.io" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1aefc0b4></div> <aside class="sidebar" data-v-1aefc0b4><div class="personal-info-wrapper" data-v-39576ba9 data-v-1aefc0b4><!----> <h3 class="name" data-v-39576ba9>
    fhtwl
  </h3> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>57</h3> <h6 data-v-39576ba9>Articles</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>64</h3> <h6 data-v-39576ba9>Tags</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/其它/" class="nav-link"><i class="undefined"></i>
  其它
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeLine/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><a href="https://github.com/fhtwl/fhtwl.github.io" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>uniapp开发app - 4.uniapp里echart的使用</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>fhtwl</span>
            
          <!---->
          2022
        </a></span></div></div> <div data-v-1aefc0b4><main class="page" style="padding-right:0;"><section><div class="page-title"><h1 class="title">uniapp开发app - 4.uniapp里echart的使用</h1> <div data-v-f875f3fc><i class="iconfont reco-account" data-v-f875f3fc><span data-v-f875f3fc>fhtwl</span></i> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>3/27/2020</span></i> <i class="iconfont reco-eye" data-v-f875f3fc><span id="/blog/uniapp/4.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-f875f3fc><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>uniapp</span><span class="tag-item" data-v-f875f3fc>vue.js</span><span class="tag-item" data-v-f875f3fc>js</span><span class="tag-item" data-v-f875f3fc>echart</span></i></div></div> <div class="theme-reco-content content__default"><h2 id="uniapp开发app-4-uniapp里echart的使用"><a href="#uniapp开发app-4-uniapp里echart的使用" class="header-anchor">#</a> uniapp开发app（4）：uniapp里echart的使用</h2> <p>这里的图表使用，其目的是兼容app端和h5端，其他端的效果并未经过测试 <br></p> <p>h5端，echart的使用方法是和pc端一样的，但是这种使用方法在app端会报错<br></p> <p>官方推荐的是，使用renderjs,这是一种运行在视图层的js，vue页面通过renderjs可以操作浏览器对象，进而可以让基于浏览器的库直接在uni-app的App端运行<br></p> <p>具体写法如下：</p> <div class="language-html extra-class"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>view</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>view</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>canvasLineBar<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:prop</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>optionBarLine<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:change:prop</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>echarts.updateEcharts<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>view</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>view</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
	<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
        <span class="token literal-property property">methods</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                uni<span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
                    <span class="token literal-property property">url</span><span class="token operator">:</span> <span class="token string">'https://www.example.com/request'</span><span class="token punctuation">,</span> <span class="token comment">//仅为示例，并非真实接口地址。</span>
                    <span class="token literal-property property">data</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                        <span class="token literal-property property">text</span><span class="token operator">:</span> <span class="token string">'uni.request'</span>
                    <span class="token punctuation">}</span><span class="token punctuation">,</span>
                    <span class="token literal-property property">header</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                        <span class="token string-property property">'custom-header'</span><span class="token operator">:</span> <span class="token string">'hello'</span> <span class="token comment">//自定义请求头信息</span>
                    <span class="token punctuation">}</span><span class="token punctuation">,</span>
                    <span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
                        <span class="token keyword">this</span><span class="token punctuation">.</span>optionBarLine<span class="token punctuation">.</span>server<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>data <span class="token operator">=</span> res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>data1
                        <span class="token keyword">this</span><span class="token punctuation">.</span>optionBarLine<span class="token punctuation">.</span>server<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span>data <span class="token operator">=</span> res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>data2
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
		<span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token punctuation">{</span>
				<span class="token literal-property property">optionBarLine</span><span class="token operator">:</span> <span class="token punctuation">{</span>
					<span class="token comment">// color: this.echartColor,</span>
					<span class="token literal-property property">tooltip</span><span class="token operator">:</span> <span class="token punctuation">{</span>
						<span class="token literal-property property">trigger</span><span class="token operator">:</span><span class="token string">'axis'</span><span class="token punctuation">,</span>
						<span class="token literal-property property">formatter</span><span class="token operator">:</span><span class="token string">'{b0}&lt;br&gt;'</span><span class="token operator">+</span>
						<span class="token string">'{a0}:{c0}kWh&lt;br&gt;'</span><span class="token operator">+</span>
						<span class="token string">'{a1}:{c1}元'</span>
					<span class="token punctuation">}</span><span class="token punctuation">,</span>
					<span class="token literal-property property">xAxis</span><span class="token operator">:</span> <span class="token punctuation">{</span>
						<span class="token literal-property property">data</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
						<span class="token literal-property property">splitArea</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 网格区域</span>
							<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">false</span> <span class="token comment">// 是否显示，默认为false</span>
						<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token literal-property property">splitLine</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// gird 区域中的分割线</span>
							<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 是否显示</span>
						<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token literal-property property">axisTick</span><span class="token operator">:</span> <span class="token punctuation">{</span>
							<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">false</span>
						<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token literal-property property">axisLine</span><span class="token operator">:</span> <span class="token punctuation">{</span>
							<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
							<span class="token literal-property property">lineStyle</span><span class="token operator">:</span> <span class="token punctuation">{</span>
								<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'hsla(0, 0%, 90%, 1)'</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token literal-property property">axisLabel</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 坐标轴的标签</span>
							<span class="token literal-property property">interval</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
							<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 是否显示</span>
							<span class="token literal-property property">inside</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 是否朝内</span>
							<span class="token literal-property property">rotate</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token comment">// 旋转角度</span>
							<span class="token literal-property property">margin</span><span class="token operator">:</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token comment">// 刻度标签与轴线之间的距离</span>
							<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'#999'</span><span class="token punctuation">,</span> <span class="token comment">// 默认轴线的颜色</span>
							<span class="token literal-property property">textStyle</span><span class="token operator">:</span> <span class="token punctuation">{</span>
								<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'#999'</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token punctuation">}</span><span class="token punctuation">,</span>
					<span class="token punctuation">}</span><span class="token punctuation">,</span>
					<span class="token literal-property property">legend</span><span class="token operator">:</span> <span class="token punctuation">{</span>
						<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
						<span class="token literal-property property">data</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'分时电量'</span><span class="token punctuation">,</span> <span class="token string">'累计电费'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
						<span class="token literal-property property">icon</span><span class="token operator">:</span> <span class="token string">'rect'</span><span class="token punctuation">,</span>
						<span class="token literal-property property">itemWith</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
						<span class="token literal-property property">itemHeight</span><span class="token operator">:</span> <span class="token number">5</span><span class="token punctuation">,</span>
					<span class="token punctuation">}</span><span class="token punctuation">,</span>
					<span class="token literal-property property">yAxis</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
							<span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">'value'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'电量'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 是否显示</span>
							<span class="token literal-property property">position</span><span class="token operator">:</span> <span class="token string">'left'</span><span class="token punctuation">,</span> <span class="token comment">// y轴位置</span>
							<span class="token literal-property property">offset</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token comment">// y轴相对于默认位置的偏移</span>
							<span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">'value'</span><span class="token punctuation">,</span> <span class="token comment">// 轴类型，默认为 ‘category’</span>
							<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'kWh'</span><span class="token punctuation">,</span> <span class="token comment">// 轴名称</span>
							<span class="token literal-property property">nameLocation</span><span class="token operator">:</span> <span class="token string">'end'</span><span class="token punctuation">,</span> <span class="token comment">// 轴名称相对位置value</span>
							<span class="token literal-property property">nameTextStyle</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 坐标轴名称样式</span>
								<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'#ccc'</span><span class="token punctuation">,</span>
								<span class="token literal-property property">padding</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">]</span> <span class="token comment">// 坐标轴名称相对位置</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
							<span class="token literal-property property">splitArea</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 网格区域</span>
								<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">false</span> <span class="token comment">// 是否显示，默认为false</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
							<span class="token literal-property property">splitLine</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// gird 区域中的分割线</span>
								<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 是否显示</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
							<span class="token literal-property property">axisTick</span><span class="token operator">:</span> <span class="token punctuation">{</span>
								<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">false</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
							<span class="token literal-property property">axisLine</span><span class="token operator">:</span> <span class="token punctuation">{</span>
								<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
								<span class="token literal-property property">lineStyle</span><span class="token operator">:</span> <span class="token punctuation">{</span>
									<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'#ccc'</span>
								<span class="token punctuation">}</span><span class="token punctuation">,</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
							<span class="token literal-property property">axisLabel</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 坐标轴的标签</span>
								<span class="token literal-property property">show</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 是否显示</span>
								<span class="token literal-property property">inside</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 是否朝内</span>
								<span class="token literal-property property">rotate</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token comment">// 旋转角度</span>
								<span class="token literal-property property">margin</span><span class="token operator">:</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token comment">// 刻度标签与轴线之间的距离</span>
								<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'#999'</span><span class="token punctuation">,</span> <span class="token comment">// 默认轴线的颜色</span>
								<span class="token literal-property property">textStyle</span><span class="token operator">:</span> <span class="token punctuation">{</span>
									<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'#999'</span>
								<span class="token punctuation">}</span><span class="token punctuation">,</span>
							<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token punctuation">}</span>
					<span class="token punctuation">]</span><span class="token punctuation">,</span>
					<span class="token literal-property property">grid</span><span class="token operator">:</span> <span class="token punctuation">[</span>
						<span class="token punctuation">{</span>
							<span class="token literal-property property">top</span><span class="token operator">:</span> <span class="token number">50</span><span class="token punctuation">,</span>
							<span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token number">80</span><span class="token punctuation">,</span>
							<span class="token literal-property property">right</span><span class="token operator">:</span> <span class="token number">80</span><span class="token punctuation">,</span>
							<span class="token literal-property property">bottom</span><span class="token operator">:</span> <span class="token number">30</span>
						<span class="token punctuation">}</span>
					<span class="token punctuation">]</span><span class="token punctuation">,</span>
					<span class="token literal-property property">series</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                        <span class="token punctuation">{</span>
							<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'分时电量'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">'bar'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">data</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
							<span class="token literal-property property">barWidth</span><span class="token operator">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
							<span class="token literal-property property">yAxisIndex</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
							<span class="token literal-property property">smooth</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
							<span class="token literal-property property">symbol</span><span class="token operator">:</span> <span class="token string">'none'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'rgba(20,170,255,1)'</span>
						<span class="token punctuation">}</span><span class="token punctuation">,</span>
						<span class="token punctuation">{</span>
							<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'累计电费'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">'line'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">data</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
							<span class="token literal-property property">smooth</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
							<span class="token literal-property property">symbol</span><span class="token operator">:</span> <span class="token string">'none'</span><span class="token punctuation">,</span>
							<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token string">'rgba(248,181,81,1)'</span>
						<span class="token punctuation">}</span>
					<span class="token punctuation">]</span>
				<span class="token punctuation">}</span><span class="token punctuation">,</span>
				<span class="token literal-property property">color</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'#ff4546'</span><span class="token punctuation">,</span> <span class="token string">'#ff9700'</span><span class="token punctuation">,</span> <span class="token string">'#57c039'</span><span class="token punctuation">,</span> <span class="token string">'#32c7ff'</span><span class="token punctuation">]</span>

			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>

	<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">module</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>echarts<span class="token punctuation">&quot;</span></span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>renderjs<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
	<span class="token keyword">let</span> myChart<span class="token punctuation">,</span> myChart1
	<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
		<span class="token function">mounted</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

			<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> window<span class="token punctuation">.</span>echarts <span class="token operator">===</span> <span class="token string">'function'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">initEcharts</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				<span class="token comment">// 动态引入较大类库避免影响页面展示</span>
				<span class="token keyword">const</span> script <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">'script'</span><span class="token punctuation">)</span>
				<span class="token comment">// view 层的页面运行在 www 根目录，其相对路径相对于 www 计算</span>
				script<span class="token punctuation">.</span>src <span class="token operator">=</span> <span class="token string">'static/js/echart/echarts.js'</span><span class="token punctuation">;</span>
				script<span class="token punctuation">.</span>onload <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">initEcharts</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				document<span class="token punctuation">.</span>head<span class="token punctuation">.</span><span class="token function">appendChild</span><span class="token punctuation">(</span>script<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>

		<span class="token punctuation">}</span><span class="token punctuation">,</span>
		<span class="token literal-property property">methods</span><span class="token operator">:</span> <span class="token punctuation">{</span>

			<span class="token function-variable function">initEcharts</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token comment">// this.chart2 = this.load_echart(this.setChartBar(data2), 'canvasLineBar');</span>
				myChart <span class="token operator">=</span> echarts<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'canvasLineBar'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token comment">// 观测更新的数据在 view 层可以直接访问到</span>
				myChart<span class="token punctuation">.</span><span class="token function">setOption</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>optionBarLine<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>

			<span class="token function">updateEcharts</span><span class="token punctuation">(</span><span class="token parameter">newValue<span class="token punctuation">,</span> oldValue<span class="token punctuation">,</span> ownerInstance<span class="token punctuation">,</span> instance</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token comment">// 监听 service 层数据变更</span>
				<span class="token keyword">if</span><span class="token punctuation">(</span>echarts<span class="token punctuation">)</span> <span class="token punctuation">{</span>
					myChart <span class="token operator">=</span> echarts<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'canvasLineBar'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
					myChart<span class="token punctuation">.</span><span class="token function">setOption</span><span class="token punctuation">(</span>newValue<span class="token punctuation">)</span>
				<span class="token punctuation">}</span>

			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>

	<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>


</code></pre></div><p>现在发现的唯一的问题，是配置项里的function无法使用,因此，很多自定义功能无法使用</p></div></section> <footer class="page-edit"><!----> <!----></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:0;" data-v-cb1513f6></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/assets/js/app.8ca67ad1.js" defer></script><script src="/assets/js/3.dc5e7bc7.js" defer></script><script src="/assets/js/1.f19b5812.js" defer></script><script src="/assets/js/52.ace084da.js" defer></script>
  </body>
</html>
